#ifndef TRAOD_H
#define TRAOD_H

#include "CalculateUtilities.h"

#define _TRAJECTORY_BEGIN_ namespace trajectory{

#define _TRAJECTORY_END_ }

/************************************************************************/
/*	This class implement the algorithm of TRAOD.						*/
/*	The reference is 'Trajectory Outlier Dectection A					*/
/*	Partition-and-Dectect Framework(ICDE2008)'							*/
/************************************************************************/

#include "headers.h"

_TRAJECTORY_BEGIN_

class Traod
{
public:
	Traod();
	/************************************************************************/
	/*	Read the data from the file and store it into m_Points.             */
	/************************************************************************/
	void readDataFromFile(const std::string& sFileName, const char delim);
	/************************************************************************/
	/*	Coarse partition the trajectories.                                  */
	/************************************************************************/
	void coarsePartition();
	/************************************************************************/
	/*	Calculate the CTR.                                                  */
	/************************************************************************/
	void calculateOP(float D, float Wper, float Wpar, float Wthe, float p);
	/************************************************************************/
	/*	Calculate the Ofrac.                                                */
	/************************************************************************/
	void calculateOfrac(float F);
	void outputResult(const std::string& strFileName);

protected:
	void split(const std::string& s, char delim, std::vector<std::string>& vStr);
	/************************************************************************/
	/*	Calculate the coarse partition by the given trajectory id.          */
	/************************************************************************/
	void calculateCoarsePartition(int iTraId);	
	float calculateMDLpar(int iTraNum, int i, int j);
	float calculateMDLnopar(int iTraNum, int i, int j);

private:
	std::vector<std::string> m_TrajectoryName;
	std::vector<std::vector<std::pair<float, float>>*> m_Points;	/*	The set	points in the trajectories.	*/
	std::vector<std::vector<std::pair<float, float>>*> m_CoarsePartition;	/*	The set of points of coarse partition.	*/
	std::vector<std::vector<std::vector<int>>> m_CTR;	/*	The set of trajectories close to Li.	*/
	std::vector<std::vector<bool>> m_OP;	/*	The set of outlier partition of trajectories.	*/
	std::vector<int> m_Ofrac;	/*	The set of outlier trajectories	*/
	int m_CardinalDetailPartition;	/*	The cardinal number of all the base unit partitions.	*/
	int m_CardinalCoarsePartition;	/*	The cardinal number of all the coarse partitions.	*/
};

_TRAJECTORY_END_

#endif